package com.icim.service.impl;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.Connection;
import org.springframework.stereotype.Service;

import com.icim.service.IShowStatusService;
import com.rabbitmq.client.AMQP.Queue.DeclareOk;
import com.rabbitmq.client.Channel;

@Service
public class ShowStatusService implements IShowStatusService {
	
	@Resource
	CachingConnectionFactory rabbitConnFactory;

	@Override
	public int getQueueDepth(String queueName) throws IOException  {
		Connection conn = rabbitConnFactory.createConnection();
		Channel channel = conn.createChannel(false);
		DeclareOk dOk = channel.queueDeclarePassive(queueName);
		int depth = dOk.getMessageCount();
		return depth;
	}

}
